package com.ruoyi.controller.achievements;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.service.achievements.AcvDepManageService;
import com.ruoyi.service.achievements.AcvEmpManageService;
import com.ruoyi.service.achievements.AcvScoringDataManageService;
import com.ruoyi.service.achievements.AcvTemplateManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zeo
 * @explain 考核数据
 * @date 2020/8/25 17:30
 */
@Controller
@RequestMapping("/acvScoringDataManage")
public class AcvScoringDataManageController extends BaseController {

    @Autowired
    AcvScoringDataManageService acvScoringDataManageService;

    @Autowired
    AcvDepManageService acvDepManageService;

    @Autowired
    AcvTemplateManageService acvTemplateManageService;

    @Autowired
    AcvEmpManageService acvEmpManageService;

    private String prefix = "achievements/scoringdatamanage";


    @GetMapping()
    public String acvScoringDataManage(ModelMap mmap) {
        mmap.put("depList", acvDepManageService.finDepList(new HashMap()));
        mmap.put("jobList", acvDepManageService.findJobList());
        mmap.put("userName", ShiroUtils.getLoginName());
        return prefix + "/acvScoringDataManage";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        return getDataTable(acvScoringDataManageService.findScoringGdData(map));
    }

    /**
     * 汇总导出
     */
    @RequestMapping("/exportSummary")
    @ResponseBody
    public AjaxResult exportSummary(String years, String months, String name, String badge, String deptId, String jobId) throws Exception {
        return acvScoringDataManageService.exportSummary(years, months, name, badge, deptId, jobId);
    }

    /**
     * 明细导出
     */
    @RequestMapping("/exportDetailed")
    @ResponseBody
    public AjaxResult exportDetailed(String scoringId) throws Exception {
        return acvScoringDataManageService.exportDetailed(scoringId);
    }

    @GetMapping("/see")
    public String see(String examineeId, String years, String months, String scoringId,String remarksTotal,String scoreTotal, ModelMap mmap) {
        mmap.put("examineeObj", acvEmpManageService.findExamineeByUserId(examineeId));
        mmap.put("years", years);
        mmap.put("months", months);
        mmap.put("scoringId", scoringId);
        mmap.put("remarksTotal", remarksTotal);
        mmap.put("scoreTotal", scoreTotal);
        return prefix + "/scoringSee";
    }

    @RequestMapping("/findSeeData")
    @ResponseBody
    public TableDataInfo findSeeData(String examineeId, String years, String months) {
        return getDataTable(acvScoringDataManageService.findGdData(examineeId, years, months));
    }

    @RequestMapping("/dataMigration")
    public void dataMigration(){
        acvScoringDataManageService.dataMigration();
    }

    @PostMapping("/back")
    @ResponseBody
    public AjaxResult back(String scoringId){
        return toAjax(acvScoringDataManageService.back(scoringId));
    }
}
